/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Jun 13, 2012  2:17:47 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.construction.memo.deduction
 * File Name : SiteDeductionProcession.java
 * TODO
 */
package apps.business.process.construction.memo.deduction;

import java.util.List;
import jpa.entitys.synchro.staging.FiApdeductionOutb;
import org.apache.log4j.Logger;
import promis.utility.CommonService;
import sap.business.fi.outbound.FiApdeductionOutbService;
import apps.business.process.SyncProcessorCommons;
import apps.promis.out.common.VwSyncSiteApDeductAction;

/**
 * @author chatree
 *
 */
public class SiteDeductionProcession  extends SyncProcessorCommons {
	
	private static final Logger log = Logger.getLogger(SiteDeductionProcession.class);
	public SiteDeductionProcession() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 * @param company
	 * @param project
	 * @param documentNo
	 * @param status
	 * @param syncIsstaging is fix value = null
	 * @throws Exception
	 */
	public void Processing(String company, String project, String documentNo, String status, String syncIsstaging) throws Exception {
		try{
			
			UPD_PROMISUseTime(true, false, null);
			List<FiApdeductionOutb> value_list = new VwSyncSiteApDeductAction().CreateToStaging(company, project, documentNo, status);
			UPD_PROMISUseTime(false, true, null);
			System.out.println("Create To Staging size=" + CommonService.getSize(value_list));
			log.info("Create To Staging size=" + CommonService.getSize(value_list));
			
			if(CommonService.getSize(value_list) > 0){
				UPD_SENDUseTime(true, false, value_list.get(0).getInstanceNo());
				new FiApdeductionOutbService().SendToSap(value_list);
				UPD_SENDUseTime(false, true, value_list.get(0).getInstanceNo());
			}			
			System.out.println("Send To SAP size=" + CommonService.getSize(value_list));
			log.info("Send To SAP size=" + CommonService.getSize(value_list));
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
	@Deprecated
	private void Start() throws Exception {
		try{
			
			String company = "SP";
			String project = "SPLVILLE-PRAGSA";
			String documentNo = "DD-1206-000059";
			String status = "O";
			String syncIsstaging = "N";
			
			List<FiApdeductionOutb> value_list = new VwSyncSiteApDeductAction().CreateToStaging(company, project, documentNo, status);
			log.info("Create To Staging...");
			
			new FiApdeductionOutbService().SendToSap(value_list);
			log.info("Send To SAP...");
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
//	/**
//	 * @param args
//	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		try{
//			
//			new SiteDeductionProcession().Start();
//			
//		}catch(Exception e)
//		{
//			e.printStackTrace();
//			log.error(e);
//		}
//	}
	
}
